﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SSM.SmartMosaicUtils.Net;
using Utils.SmartMosaicServerWebservice;

namespace smart_test
{
    public partial class UploadFrm : Form
    {
        public delegate void NoArgumentDelegate(UploadResult uploadResult);

        //public bool themeLove = false;
        //public bool themeAnimal = false;
        //public bool themeScenery = false;
        //public bool themeCelebrity = false;

        int themeCode;

        public string filename;

        public UploadFrm(string _filename)
        {
            InitializeComponent();
            filename = _filename;
        }

        /// <summary>
        /// 테마 '사랑'을 클릭하였을 경우
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btLove_Click(object sender, EventArgs e)
        {
            UploadPanel.Visible = true;

            UploadPanel.Visible = true;

            themeCode = 1;

            Timer timer = new Timer();
            timer.Interval = 200;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Enabled = true;
        }

        /// <summary>
        /// 테마 '동물'을 클릭하였을 경우
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btAnimal_Click(object sender, EventArgs e)
        {
            UploadPanel.Visible = true;

            UploadPanel.Visible = true;

            themeCode = 4;

            Timer timer = new Timer();
            timer.Interval = 200;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Enabled = true;
        }

        /// <summary>
        /// 테마 '풍경'을 클릭하였을 경우
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btScenery_Click(object sender, EventArgs e)
        {
            UploadPanel.Visible = true;

            UploadPanel.Visible = true;

            themeCode = 2;

            Timer timer = new Timer();
            timer.Interval = 200;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Enabled = true;
        }

        /// <summary>
        /// 테마 '유명인'을 클릭하였을 경우
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btCelebrity_Click(object sender, EventArgs e)
        {
            //pbImageProcessing.Visible = true;
            UploadPanel.Visible = true;

            themeCode = 3;

            Timer timer = new Timer();
            timer.Interval = 200;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Enabled = true;

        }

        void timer_Tick(object sender, EventArgs e)
        {
            (sender as Timer).Dispose();

            FileUploader fileUploader = new FileUploader();

            UploadResult uploadResult = fileUploader.UploadFile(
                filename,
                themeCode
                );

            this.Invoke(
                new NoArgumentDelegate(FileDownloadCompleted),
                uploadResult
                );
        }

        public void FileDownloadCompleted(UploadResult uploadResult)
        {
            ViewFrm frm = new ViewFrm(uploadResult.Detail);
            frm.Show();

            this.Close();
        }

        private void btLove_MouseUp(object sender, MouseEventArgs e)
        {
            btLovePress.Visible = false;
        }

        private void btLove_MouseDown(object sender, MouseEventArgs e)
        {
            btLovePress.Visible = true;
        }

        private void btAnimal_MouseDown(object sender, MouseEventArgs e)
        {
            btAnimalPress.Visible = true;
        }

        private void btAnimal_MouseUp(object sender, MouseEventArgs e)
        {
            btAnimalPress.Visible = false;
        }

        private void btScenery_MouseUp(object sender, MouseEventArgs e)
        {
            btSceneryPress.Visible = false;
        }

        private void btScenery_MouseDown(object sender, MouseEventArgs e)
        {
            btSceneryPress.Visible = true;
        }

        private void btCelebrity_MouseDown(object sender, MouseEventArgs e)
        {
            btCelebrityPress.Visible = true;
        }

        private void btCelebrity_MouseUp(object sender, MouseEventArgs e)
        {
            btCelebrityPress.Visible = false;
        }
    }
}
